;(function(){
  'use strict';
  angular.module('controllers.omdisplay.sysBusStat')
    .controller('TradePercentageCtrl',tradePercentageCtrl)
    .controller('TradePercentageViewCtrl',tradePercentageViewCtrl); 
  /**
   * 交易总量占比Form控制器
   * @param   $scope                   当前controller作用域     
   * @param   TradeRatioSelector       交易总量占比下拉选service
   * @param   TradeRatioQueryObj       交易总量占比查询参数及方法service
   */
  function tradePercentageCtrl($scope,TradeRatioSelector,TradeRatioQueryObj){

    //初始化查询条件选择框对象
    $scope.selector = TradeRatioSelector.selector;
    //初始化查询参数对象
    $scope.tradePercentage = TradeRatioQueryObj.initParam();
    //初始化日期对象
    $scope.date = TradeRatioQueryObj.initDate();
    //初始化页面显示控制变量对象
    $scope.flag = TradeRatioQueryObj.initFlag();
    //是否分省切换方法
    $scope.changeProvincial = TradeRatioQueryObj.changeProvincialFn;
    //交易总量占比数据查询方法  
    $scope.tradePercentageQuery = TradeRatioQueryObj.queryFn;   
    //监听账期选项存在改变则重新初始化日期条件
    $scope.$watch('tradePercentage.timeType',function(newValue,oldValue){
      if(newValue === oldValue){
        return;
      }
      $scope.date = TradeRatioQueryObj.initDate();
    },true);
    //监听form时间广播获取季度验证flag
    $scope.$on('formInvalid',function(eo,flag){
      $scope.quarterInvalid = flag;
    });

  }

  tradePercentageCtrl.$inject = ['$scope','TradeRatioSelector','TradeRatioQueryObj'];

  /**
   * 交易总量占比显示控制器
   * @param   $scope            当前作用域
   * @param   TradeRatioViewObj 交易总量占比页面数据service
   */
  function tradePercentageViewCtrl($scope,TradeRatioViewObj,$mdDialog){
    //初始化页面展示控制对象并绑定到$scope上
    $scope.viewObj = TradeRatioViewObj.initViewObj();
    //初始化刷新echarts实例
    TradeRatioViewObj.initChartObj();
    //业务量echarts图切换
    $scope.businessAmount = function(){
      $scope.viewObj.queryType = 1;
    };
    //订单金额echarts图切换
    $scope.orderMoney = function(){
      $scope.viewObj.queryType = 2;
    };
    //充值金额echarts图切换
    $scope.rechargeMoney = function(){
      $scope.viewObj.queryType = 3;
    };
    //控制器销毁时重新初始化图表对象
    $scope.$on('$destroy',function(){
      TradeRatioViewObj.destroyChartObj();
      $mdDialog.cancel();
    });
  }

  tradePercentageViewCtrl.$inject = ['$scope','TradeRatioViewObj','$mdDialog'];
})();